package com.randi.system.service.impl.sysLog;

import com.github.pagehelper.PageInfo;
import com.randi.common.constant.CacheConstants;
import com.randi.common.utils.SecurityUtils;
import com.randi.system.domain.entity.sysLog.SysLogOperate;
import com.randi.system.domain.params.sysLog.SysLogOperateParam;
import com.randi.system.mapper.sysLog.SysLogOperateMapper;
import com.randi.system.service.sysLog.ISysLogOperateService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author ziye
 */
@Service
@CacheConfig(cacheNames = CacheConstants.SYS_LOG_OPERATE)
public class SysLogOperateServiceImpl implements ISysLogOperateService {

    @Resource
    private SysLogOperateMapper sysLogOperateMapper;

    /**
     * 分页查询业务列表
     *
     * @param sysLogOperateParam 检索参数
     * @return 业务集合
     */
    @Override
    @Cacheable(keyGenerator = "baseKeyGenerator", unless = "#result == null")
    public PageInfo<SysLogOperate> selectPageList(SysLogOperateParam sysLogOperateParam) {
        return new PageInfo<>(sysLogOperateMapper.selectSysLogOperateList(sysLogOperateParam));
    }

    /**
     * 查看详情
     *
     * @return 业务集合
     */
    @Override
    @Cacheable(key = "#operationId", unless = "#result == null")
    public SysLogOperate selectSysLogOperateById(Long operationId) {
        return sysLogOperateMapper.selectSysLogOperateById(operationId);
    }

    /**
     * 插入数据
     *
     * @param sysLogOperate sysLogOperate
     * @return 结果
     */
    @Override
    @CacheEvict(allEntries = true, beforeInvocation = true)
    public int insertSysLogOperate(SysLogOperate sysLogOperate) {
        SecurityUtils.setInsertInfo(sysLogOperate);
        sysLogOperate.setUpdateBy(null);
        sysLogOperate.setUpdateTime(null);
        return sysLogOperateMapper.insert(sysLogOperate);
    }

    /**
     * 更新数据
     *
     * @param sysLogOperate SysLogOperate
     * @return 结果
     */
    @Override
    @CacheEvict(allEntries = true, beforeInvocation = true)
    public int updateSysLogOperate(SysLogOperate sysLogOperate) {
        return sysLogOperateMapper.updateById(sysLogOperate);
    }

    /**
     * 批量删除数据
     *
     * @param ids ids
     * @return status
     */
    @Override
    @CacheEvict(allEntries = true, beforeInvocation = true)
    public int deleteBatchSysLogOperate(List<Long> ids) {
        return sysLogOperateMapper.deleteBatchIds(ids);
    }

}
